package com.whfc.wxmp.api.fse.controller;

import com.whfc.common.result.ListData;
import com.whfc.common.result.R;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.wxmp.annotation.CurrentWxUser;
import com.whfc.fse.dto.FseCraneDTO;
import com.whfc.fse.dto.FseCraneDataDTO;
import com.whfc.fse.dto.FseCraneDataLogDTO;
import com.whfc.fse.dto.FseCraneFvsDeviceDTO;
import com.whfc.fuum.entity.SysUser;
import com.whfc.fuum.entity.WxUser;
import com.whfc.wxmp.api.fse.service.WxFseCraneService;
import com.whfc.wxmp.util.RequestConetxtUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author qzexing
 * @version 1.0
 * @date 2021/11/4 16:32
 */
@RestController
@RequestMapping("/mp/api/fse/crane")
public class WxFseCraneController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxFseCraneService wxFseCraneService;

    @GetMapping("/list")
    public Result list(@CurrentWxUser WxUser loginUser,
                       @RequestParam("deptId") Integer deptId) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                loginUser.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "查询塔机设备列表", RequestConetxtUtil.getParameters());
        ListData<FseCraneDTO> listData = wxFseCraneService.list(deptId);
        return ResultUtil.success(listData);
    }

    @GetMapping("/list/v2")
    public R<List<FseCraneDTO>> listV2(@CurrentWxUser WxUser loginUser,
                       @RequestParam("deptId") Integer deptId) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                loginUser.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "查询塔机设备列表", RequestConetxtUtil.getParameters());
        List<FseCraneDTO> listData = wxFseCraneService.listV2(deptId);
        return R.success(listData);
    }


    @GetMapping("/latest")
    public Result latest(@CurrentWxUser WxUser loginUser,
                         @RequestParam("craneId") Integer craneId) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                loginUser.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "获取塔机实时数据", RequestConetxtUtil.getParameters());
        FseCraneDataDTO fseCraneDataDTO = wxFseCraneService.latest(craneId);
        return ResultUtil.success(fseCraneDataDTO);
    }


    @GetMapping(value = "/log", params = "date")
    public Result log(@CurrentWxUser WxUser loginUser,
                      @RequestParam("craneId") Integer craneId,
                      @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam("date") Date date) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                loginUser.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "查询塔机历史列表", RequestConetxtUtil.getParameters());
        ListData<FseCraneDataLogDTO> listData = wxFseCraneService.log(craneId, date);
        return ResultUtil.success(listData);
    }

    @GetMapping("/fvs/list")
    public Result fvsList(@CurrentWxUser WxUser user,
                          @RequestParam("craneId") Integer craneId) {
        logger.info("获取视频监控列表，loginer:{},craneId:{}", user.getName(), craneId);
        List<FseCraneFvsDeviceDTO> fvsList = wxFseCraneService.fvsList(craneId);
        return ResultUtil.success(new ListData<>(fvsList));
    }

}
